package com.unohacha.qqj.fzdr.ui.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.qpg.superhttp.SuperHttp;
import com.qpg.superhttp.callback.SimpleCallBack;
import com.unohacha.qqj.fzdr.R;
import com.unohacha.qqj.fzdr.SupplyDemandTypeActivity;
import com.unohacha.qqj.fzdr.adapter.CityLabelCategaryAdapter;
import com.unohacha.qqj.fzdr.adapter.LabelCategaryAdapter;
import com.unohacha.qqj.fzdr.bean.BaseBean;
import com.unohacha.qqj.fzdr.bean.LabelBean;
import com.unohacha.qqj.fzdr.bean.find.FindDetailBean;
import com.unohacha.qqj.fzdr.fabu.ZhizaoActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.EquipmentSupplyActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.FabricCateActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.FabricSupplyActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.FindJobActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.LeaseOfHousesActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.RawMaterialActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.RecruitmentActivity;
import com.unohacha.qqj.fzdr.ui.activity.supply.TextileEquipmentActivity;
import com.unohacha.qqj.fzdr.util.GlideImageLoader;
import com.unohacha.qqj.fzdr.util.Prefer;
import com.unohacha.qqj.fzdr.view.MyGridView;
import com.unohacha.qqj.mylibrary.base.BaseActivity;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

public class PubManageDetialActivity extends BaseActivity {
    @BindView(R.id.common_back)
    ImageView commonBack;
    @BindView(R.id.common_title)
    TextView commonTitle;
    @BindView(R.id.tv_pub_time)
    TextView tvPubTime;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_num)
    TextView tvNum;
    @BindView(R.id.tv_type)
    TextView tvType;
    @BindView(R.id.tv_price)
    TextView tvPrice;
    @BindView(R.id.tv_fukuan)
    TextView tvFukuan;
    @BindView(R.id.tv_content)
    TextView tvContent;
    @BindView(R.id.tv_edit)
    TextView tvEdit;
    @BindView(R.id.tv_remain_time)
    TextView tvRemainTime;
    @BindView(R.id.gv_sing_style)
    MyGridView gridView;
    @BindView(R.id.common_right_image)
    ImageView commonRightImage;
    @BindView(R.id.banner)
    Banner banner;
    private String id;
    private String supply_cate_id;
    ArrayList<String> listsCateName;
    ArrayList<FindDetailBean.DataBean.RegionBean> listLabel;
    CityLabelCategaryAdapter cityLabelCategaryAdapter;
    private String label="";
    FindDetailBean.DataBean dataBean;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_pub_manage_detial;
    }

    @Override
    protected void initData() {
        super.initData();
        commonTitle.setText("查看");
        commonTitle.setVisibility(View.INVISIBLE);
        label=getIntent().getStringExtra("label");
        commonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        id=getIntent().getStringExtra("id");
        supply_cate_id=getIntent().getStringExtra("supply_cate_id");
        tvEdit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               switch (label){
                   case "纺织面料":
                       Intent intent1=new Intent(PubManageDetialActivity.this, FabricSupplyActivity.class);
                       intent1.putExtra("name",dataBean.getSupply_cate_id());
                       intent1.putExtra("main_id","1");
                       intent1.putExtra("id",dataBean.getSupply_cate_id_id()+"");
                       intent1.putExtra("info",dataBean);
                       startActivity(intent1);
                       break;
                   case "纺织织造":
                       Intent intent=new Intent(PubManageDetialActivity.this, ZhizaoActivity.class);
                       intent.putExtra("id",id+"");
                       intent.putExtra("type","1");
                       startActivity(intent);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;

                   case "设备维修":
                       Intent intent3=new Intent(PubManageDetialActivity.this, EquipmentSupplyActivity.class);
                       intent3.putExtra("id",id+"");
                       intent3.putExtra("type","1");
                       startActivity(intent3);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;

                   case "人才招聘":
                       Intent intent4=new Intent(PubManageDetialActivity.this, RecruitmentActivity.class);
                       intent4.putExtra("id",id+"");
                       intent4.putExtra("type","1");
                       startActivity(intent4);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;

                   case "纺织原料":
                       Intent intent5=new Intent(PubManageDetialActivity.this, RawMaterialActivity.class);
                       intent5.putExtra("id",id+"");
                       intent5.putExtra("type","1");
                       startActivity(intent5);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;

                   case "人员求职":
                       Intent intent6=new Intent(PubManageDetialActivity.this, FindJobActivity.class);
                       intent6.putExtra("id",id+"");
                       intent6.putExtra("type","1");
                       startActivity(intent6);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;
                   case "房屋租赁":
                       Intent intent7=new Intent(PubManageDetialActivity.this, LeaseOfHousesActivity.class);
                       intent7.putExtra("id",id+"");
                       intent7.putExtra("type","1");
                       startActivity(intent7);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;
                   case "纺织设备":
                       Intent intent8=new Intent(PubManageDetialActivity.this, TextileEquipmentActivity.class);
                       intent8.putExtra("id",id+"");
                       intent8.putExtra("type","1");
                       startActivity(intent8);
                       // jumpToOtherActivity(this, ZhizaoActivity.class);
                       break;
               }
            }
        });
        getData();
    }

    private void getData(){
        showLoading();
        Map<String, String> params = new HashMap<>();
        params.put("id", id);
        params.put("supply_cate_id", supply_cate_id);
        params.put("address_id", Prefer.obtainReLocation(this));
        params.put("token", Prefer.getInstance().getToken());
        SuperHttp.post("api/supplyinfo/supplyDetail")
                .addParams(params)
                .request(new SimpleCallBack<BaseBean<FindDetailBean.DataBean>>() {
                    @Override
                    public void onSuccess(BaseBean<FindDetailBean.DataBean> data) {
                        hideLoading();
                        if(data.getCode()==1){
                            dataBean=data.getData();
                            setBannerData(data.getData().getList_pic());
                            tvTitle.setText(data.getData().getTitle());
                            tvPubTime.setText(data.getData().getCreate_time());
                            tvType.setText("分类："+data.getData().getSupply_cate_id());
                    //        tvNum.setText(data.getData().getNums()+data.getData().getNums());
                            tvPrice.setText(data.getData().getPrice()+data.getData().getPrice_company());
                            tvFukuan.setText(data.getData().getBreadth()+data.getData().getBreadth_company());
                            tvContent.setText(data.getData().getContent());
                      //      tvRemainTime.setText(data.getData().getRelease_days());
                            listLabel=new ArrayList<>();
                            if(data.getData().getRegion()!=null){
                                for(int i=0;i<data.getData().getRegion().size();i++){

                                }
                                listLabel.addAll(data.getData().getRegion());

                                cityLabelCategaryAdapter=new CityLabelCategaryAdapter(PubManageDetialActivity.this,listLabel);
                                gridView.setAdapter(cityLabelCategaryAdapter);
                            }

                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {

                        hideLoading();
                    }
                });

    }

    //设置banner 数据
    private void setBannerData(List<String> mBannerList) {

        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);//设置圆形指示器与标题
        banner.setIndicatorGravity(BannerConfig.CENTER);//设置指示器位置
        banner.setImages(mBannerList);
        banner.setImageLoader(new GlideImageLoader());
        banner.start();

        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                //用mBannerAllList集合
            }
        });
    }
}
